<template>
  <div :class="isHide ? 'audioBox' : 'audioBoxTe'">
    <div class="showOrhide">
      <div class="showOrHideBtn" @click="switchIsHide"></div>
    </div>
    <div class="audioContent">
      <aplayer
        class="audioDom"
        ref="audioDom"
        :audio="musicList"
        :lrcType="1"
        :listFolded="true"
        :listMaxHeight="200"
        @error="errorFn"
        @canplay="getMusciDetail"
      />
      <i
        class="listSwitch iconfont icon-mulu"
        @click="listIsHide = !listIsHide"
      ></i>
      <ul :class="listIsHide && 'musicListHide'" class="musicList">
        <li
          v-for="(item, index) in musicList"
          :key="index"
          :class="musicId == item.id && 'musicItemTe'"
          class="musicItem"
          @click="switchMusic(index)"
        >
          <span class="musicName">{{ item.name }} </span>
          <span class="musicArtist">{{ item.artist }}</span>
          <span class="musicdelBtn" @click.stop="delMusic(item.id)"></span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      isHide: true,
      listIsHide: true,
      musicId: "",
    };
  },
  computed: {
    ...mapState("musicStore", ["musicList"]),
  },
  mounted() {
    this.$bus.$on("playCurrentMusic", () => {
      this.$refs.audioDom.switch(0);
      this.$refs.audioDom.play();
    });
  },
  methods: {
    ...mapActions("musicStore", ["delMusicAction"]),
    switchIsHide() {
      this.isHide = !this.isHide;
    },
    errorFn(obj) {
      this.delMusicAction(this.$refs.audioDom.currentMusic.id);
      this.$nextTick(() => {
        this.$refs.audioDom.skipForward();
      });
    },
    //切换音乐
    switchMusic(index) {
      this.$refs.audioDom.switch(index);
      this.musicId = this.musicList[index].id;
    },
    //实时获取当前播放的音乐
    getMusciDetail() {
      this.musicId = this.$refs.audioDom.currentMusic.id;
    },
    //删除音乐
    delMusic(id) {
      this.delMusicAction(id);
    },
  },
};
</script>

<style lang="scss" scoped>
.audioBox {
  height: 60px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: -60px;
  background-image: linear-gradient(#363636, #242424);
  width: 100%;
  transition: all 600ms;
  z-index: 9999;
  &:hover {
    bottom: 0;
    transition: all 600ms;
  }
}
.audioBoxTe {
  height: 60px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: linear-gradient(#363636, #242424);
  width: 100%;
  z-index: 9999;
}
.showOrhide {
  height: 20px;
  position: absolute;
  left: 0;
  right: 0;
  top: -20px;
  .showOrHideBtn {
    background: url("./../../assets/imges/auidoIcon.png") no-repeat 0 -380px;
    width: 52px;
    height: 20px;
    float: right;
    margin-right: 15px;
  }
}
.audioContent {
  width: 980px;
  margin: 0 auto;
  position: relative;
  border-top: 1px solid #363636;
  .audioDom {
    overflow: visible;
    background-image: linear-gradient(#363636, #242424);
    box-shadow: none;
    /deep/.aplayer-body {
      .aplayer-icon-menu {
        display: none !important;
      }
      .aplayer-info {
        padding: 0 7px 0 5px;
        border: none;
        height: 50px;
        margin-left: 66px;
        .aplayer-music {
          color: #e8e8e8;
          text-align: left;
          margin: 3px 0 10px 5px;
        }
        .aplayer-lrc {
          background: #363636;
          position: absolute;
          right: 0;
          width: 400px;
          transition: all 600ms;
          height: 200px;
          display: block;
          margin-bottom: 0;
          bottom: 55px;
          .aplayer-lrc-contents {
            margin-top: 50px;
          }
          .aplayer-lrc-current {
            color: #fff;
          }
          &::after {
            display: none;
          }
          &::before {
            display: none;
          }
        }
        .aplayer-icon.aplayer-icon-lrc {
          display: inline-block;
        }
      }
      .aplayer-pic {
        width: 50px;
        height: 50px;
      }
    }
  }
  /deep/.aplayer.aplayer-withlrc .aplayer-lrc {
    height: 0 !important;
  }
}

.musicList {
  color: #ccc;
  height: 200px;
  transition: all 0.5s;
  overflow: auto;
  background: #2a2a2a;
  position: absolute;
  bottom: 100%;
  width: 580px;
  left: 0;
}
.musicListHide {
  height: 0;
}
.musicItem {
  cursor: pointer;
  display: flex;
  border-bottom: 1px solid #ccc;
  text-align: left;
  font-size: 12px;
  overflow: hidden;
  align-items: center;
  .musicName {
    margin-left: 10px;
    width: 350px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding-left: 10px;
    height: 28px;
    line-height: 28px;
    box-sizing: border-box;
  }
  .musicArtist {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .musicdelBtn {
    display: block;
    width: 13px;
    height: 16px;
    background: url("./../../assets/imges/iconThere.png") no-repeat -51px 0;
    margin-right: 10px;
  }
}
.musicItemTe {
  background: #fff;
  color: #333;
  &::before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 20px;
    background: red;
  }
}
.listSwitch {
  position: absolute;
  display: inline-block;
  right: -5px;
  bottom: 5px;
  z-index: 999;
  width: 12px;
  height: 16px;
  color: #5a5a5a;
  font-size: 12px;
  &:hover {
    color: #000;
  }
}

.musicList::-webkit-scrollbar {
  /* width: 0px; */
  width: 3px;
  height: 3px;
}

/*外层轨道。可以用display:none让其不显示，也可以添加背景图片，颜色改变显示效果*/

.musicList::-webkit-scrollbar-track {
  width: 3px;
  background-color: #999;
  -webkit-border-radius: 2em;
  -moz-border-radius: 2em;
  border-radius: 2em;
}

/*滚动条的设置*/

.musicList::-webkit-scrollbar-thumb {
  background-color: #606d71;
  background-clip: padding-box;
  min-height: 28px;
  -webkit-border-radius: 2em;
  -moz-border-radius: 2em;
  border-radius: 2em;
}
/*滚动条移上去的背景*/

.musicList::-webkit-scrollbar-thumb:hover {
  background-color: #fff;
}
</style>